package com.hyd.tweet.twitter;

import twitter4j.TwitterException;

import java.util.HashMap;
import java.util.Map;

/**
 * Translate error codes to text messages
 *
 * @author yiding.he
 */
public class TwitterExceptionParser {
    
    private static final Map<Integer, String> STATUSCODE_MAP = new HashMap<Integer, String>();
    
    static {
        STATUSCODE_MAP.put(404, "目标不存在");
        STATUSCODE_MAP.put(403, "操作被拒绝");
        STATUSCODE_MAP.put(500, "推特暂时出现故障，无法处理本次请求");
        STATUSCODE_MAP.put(502, "推特服务暂时不可用");
        STATUSCODE_MAP.put(503, "推特服务器暂时过载（是的，鲸鱼了）");
    }

    public static String parse(TwitterException e) {
        if (STATUSCODE_MAP.containsKey(e.getStatusCode())) {
            return STATUSCODE_MAP.get(e.getStatusCode());
        } else {
            return "错误代码 " + e.getStatusCode() + "(" + e.getMessage() + ")";
        }
    }
}
